<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改事项')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style>
        #dept{
            display: none;
        }

        * {
            margin: 0;
            padding: 0;
        }
        #_zeren{
            display: none;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-matter-edit" th:object="${lkMatter}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">事项名称：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{name}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">事项分类：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input th:value="${lkMatter.typeId}" name="typeId" type="hidden" />
                    <input name="typeName" class="form-control" th:value="${lkMatter.typeName}" type="text" onclick="selectTypeTree()" id="typeName" placeholder="请选择事项类型 " required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">责任单位类型：</label>
            <div class="col-sm-8">
                <label class="radio-box" for="com" > <input th:field="*{orgStatus}" id="com"  type="radio" name="orgStatus" value="0" checked="checked" /> 企业 </label>
                <label class="radio-box" for="dep" > <input th:field="*{orgStatus}"  id="dep" type="radio" name="orgStatus" value="1" /> 部门 </label>
            </div>
        </div>

        <div class="form-group" id="dept">
            <label class="col-sm-3 control-label">责任部门：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input type="hidden" id="deptTreeId" th:value="${lkMatter.deptTreeId}"/>
                    <input onclick="selectDeptTree()" th:value="${lkMatter.deptName}" id="deptName" type="text" placeholder="请选择责任部门" class="form-control" >
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group" id="_zeren">
            <label class="col-sm-3 control-label">责任人：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input name="approveUser" id="treeId" type="hidden" th:value="${lkMatter.approveUser}"/>
                    <input name="approveUsername" th:value="${lkMatter.approveUsername}" onclick="selectUserTree()" id="treeName" type="text" placeholder="请选择审批人" class="form-control" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-8">
                <input name="sort" th:field="*{sort}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">红灯预警天数：</label>
            <div class="col-sm-8">
                <input name="redLightDays" th:field="*{redLightDays}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">黄灯预警天数：</label>
            <div class="col-sm-8">
                <input name="yelLightDays" th:field="*{yelLightDays}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">预计完成时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="expectedDate" th:value="${#dates.format(lkMatter.expectedDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">简介：</label>
            <div class="col-sm-8">
                <textarea id="matterContent"  class="form-control" th:text="${lkMatter.matterContent}"></textarea>
            </div>
        </div>-->
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:src="@{/js/comboTreePlugin.js}"></script>
<script type="text/javascript">
    var prefix = ctx + "linkong/matter";

    $(function (){
        var orgStatus = $('input:radio:checked').val();
        if (orgStatus == 0){
            document.getElementById("dept").style.display="none";
        } else if (orgStatus == 1){
            document.getElementById("dept").style.display="block";
            document.getElementById("_zeren").style.display="block";
        }
    })

    $("#form-matter-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }

    function edit() {
        var id = $("input[name='id']").val();
        var orgStatus = $('input:radio:checked').val();
        var name = $("input[name='name']").val();
        var typeId = $("input[name='typeId']").val();
        var approveUser = $("input[name='approveUser']").val();
        var approveUsername = $("input[name='approveUsername']").val();
        var sort = $("input[name='sort']").val();
        var redLightDays = $("input[name='redLightDays']").val();
        var yelLightDays = $("input[name='yelLightDays']").val();
        var expectedDate = $("input[name='expectedDate']").val();
        // var matterContent = $('#matterContent').val();
        var mainOrg = "";
        var mainOrgname = "";
       if (orgStatus == 1){
            mainOrg = $("input[id='deptTreeId']").val();
            mainOrgname = $("input[id='deptName']").val();
        }
        $.ajax({
            cache : true,
            type : "POST",
            url : prefix + "/edit",
            data : {
                "id":id,
                "name": name,
                "typeId": typeId,
                "approveUser": approveUser,
                "approveUsername": approveUsername,
                "orgStatus": orgStatus,
                "mainOrg": mainOrg,
                "mainOrgname": mainOrgname,
                "sort": sort,
                "redLightDays": redLightDays,
                "yelLightDays": yelLightDays,
                "expectedDate": expectedDate
                // ,"matterContent": matterContent
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    /*新增-选择事项分类树*/
    function selectTypeTree() {
        var id = $("#typeId").val();
        var typeTreeId = id > 0 ? id : 1;
        var url = prefix + "/selectTypeTree/" + typeTreeId;
        var options = {
            title: '事项分类选择',
            width: "380",
            url: url,
            callBack: doTypeSubmit
        };
        $.modal.openOptions(options);
    }

    function doTypeSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#typeId").val(body.find('#typeId').val());
        $("#typeName").val(body.find('#typeName').val());
        layer.close(index);
    }

    /*新增-选择责任部门树*/
    function selectDeptTree() {
        var id = $("#deptTreeId").val();
        var deptId = $.common.isEmpty(id) ? "100" : $("#deptTreeId").val();
        var url = prefix + "/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doDeptSubmit
        };
        $.modal.openOptions(options);
    }

    function doDeptSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#deptTreeId").val(body.find('#deptTreeId').val());
            $("#deptName").val(body.find('#deptName').val());
            layer.close(index);
        }
    }

    /*新增-选择领导人树*/
    function selectUserTree() {
        var treeId = $("#treeId").val();
        var deptUserId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url =prefix + "/selectDeptUserTree/" + deptUserId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doUserSubmit
        };
        $.modal.openOptions(options);
    }

    function doUserSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;

        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
    $("input[name='expectedDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });



    $(function(){
        $('input').on('ifChecked', function(event){
            var menuType = $(event.target).val();
            if(menuType == '1'){
                $('#dept').show();
                $('#_zeren').show();
            }else{
                $('#dept').hide();
                $('#_zeren').hide();
            }
        })
    })

</script>
</body>
</html>